class Category < ActiveRecord::Base
  has_many :products, :through => :product_categories
  has_many :product_categories

  before_destroy :check_for_products

  validates :name, :presence => { :message => 'Debe ingresar un nombre' }

  default_scope order('listing_order')

  def check_for_products
    if self.products.count > 0
      self.errors.add_to_base("La categoría está asociada a productos.")
      return false
    end
  end
end
